package com.se.server;

import com.se.exception.ConnectionExistException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.Socket;
import java.util.concurrent.ConcurrentHashMap;

public class SocketSet {
    private final ConcurrentHashMap<String, Socket> sockets = new ConcurrentHashMap<>();
    private static final Logger logger = LoggerFactory.getLogger(SocketSet.class);

    public void addSocket(String socketType, Socket socket) throws ConnectionExistException {
        if(sockets.containsKey(socketType)){
            logger.error("尝试建立的连接已存在！");
            throw new ConnectionExistException("该连接已存在");
        }
        sockets.put(socketType, socket);
    }

    public Socket getSocket(String socketType){
        return sockets.get(socketType);
    }
}
